package com.atguigu01.lamda;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class LamudaTest {
    public static void main(String[] args) {
//        int[] nums=new int[]{7,1,5,3,6,4};
//        System.out.println(maxProfit(nums));

        String s = "rat";
        String t = "cat";
        System.out.println(isAnagram(s, t));

        System.out.println(isHappy(19));

    }
    public static boolean isHappy(int n) {
        for (int i = 0; i < 15; i++) {
            if(method(n)==1){
                return true;
            }
            n=method(n);
        }
        return false;

    }

    public static int method(int n){
        int result=0;
        while(n!=0){
            result+=(n%10)*(n%10);
            n=n/10;
        }
        return result;
    }


    public static boolean isAnagram(String s, String t) {
        HashMap<Character,Integer> maps=new HashMap<>();

        char[] arrs=s.toCharArray();
        char[] arrt=t.toCharArray();

        for (int i = 0; i <arrs.length ; i++) {
            if(!maps.containsKey(arrs[i])){
                maps.put(arrs[i],1);
            }else{
                int count=maps.get(arrs[i]);
                count++;
                maps.put(arrs[i],count);
            }
        }
        for (int i = 0; i <arrt.length ; i++) {
            if(!maps.containsKey(arrt[i])){
                maps.put(arrt[i],1);
            }else{
                int count=maps.get(arrt[i]);
                count--;
                maps.put(arrt[i],count);
            }
        }
        for (Map.Entry<Character, Integer> values:maps.entrySet()
             ) {
            System.out.println(values);
        }

        for (int val:maps.values()
             ) {
            if(val!=0){
                return false;
            }
        }
      return true;

    }

    public static int maxProfit(int[] prices) {
        int count=0;
        for (int i = 0; i <prices.length-1 ; i++) {
            if(prices[i]>=prices[i+1]){
                count++;
            }else{
                break;
            }
        }
        if(count==prices.length-1){
            return 0;
        }else{
            int maxinterest=0;
            for (int i = 0; i <prices.length-1 ; i++) {
                int buyprice=prices[i];
                for (int j = i+1; j < prices.length; j++) {
                    int sellprice=prices[j];
                    if(sellprice-buyprice<=0){
                        continue;
                    }
                    if(sellprice-buyprice>maxinterest){
                        maxinterest=sellprice-buyprice;
                    }
                }
            }
            return maxinterest;
        }


    }

}
